package com.netflix.service.user.controller;

import com.basic.pojo.user.User;
import com.google.common.collect.ImmutableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public List<User> getUsers() {
        User user = new User();
        user.setId(1);
        user.setName("jason");
        user.setSex(1);
        return ImmutableList.of(user);
    }

    @RequestMapping(value = "/shopping/items", method = RequestMethod.GET)
    public Object getUserShoppingItems(@RequestParam("userId") int userId) {
        Object response = restTemplate.getForObject("http://shopping-service/shopping/items", List.class);
        return response;
    }
}
